﻿using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using FDEE.Model;
using FDEEInterface;
using FDEEPublicFunc;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FDEEDrawingModels
{
    public class PloterBeamTable
    {
        static string _dwgPath = "";//构造物
        static string _blcName = "MI12";
        static double A3Height = 297 - 10 - Extensions.bottomHeight;
        static double intervalHeight = 26;//小于块高度设置高度
        static double tbH = 0;

        static double lastMegerHeight = 0;

      
        /// <summary>
        /// 绘制盖梁钢筋
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ret"></param>
        /// <param name="eType"></param>
        /// <param name="dwgPath"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="capLength"></param>
        /// <param name="pierName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <param name="pageNo"></param>
        /// <param name="scale"></param>
        /// <param name="title"></param>
        public static void DrawingCapBeamTableNew(Database db, MemberBase ret, EStructure eType, string dwgPath,
    string typeName, string structureName, string capLength, string pierName, FDEE.Model.eSubType type, ref int pageCount, int pageNo = 0, int scale = 1, string title = "MAINLINE")
        {
            if (ret == null || ret.RebarList == null || ret.RebarList.Count == 0)
            {
                throw new Exception("数据异常");
            }
            _dwgPath = dwgPath;

            Extents2d ext = new Extents2d(Point2d.Origin, Point2d.Origin);
            Point2d CT = Point2d.Origin.Convert2D(0, -297 * pageNo);
            Point2d M1 = CT.Convert2D(0, -2 * scale);

            #region 分页处理
            List<RebarCollection> divDic = new List<RebarCollection>();
            if (typeName.Contains("PE") || typeName.Contains("PL"))
            {
                CalcBeamPage(ret.RebarList, scale, ref divDic);
            }
            else
                CalcBeamPage(ret.RebarList, scale, ref divDic);
            #endregion
            pageCount = divDic.Count;
            #region 绘制表格
            Table lasTb = new Table();
            for (int i = 0; i < divDic.Count; i++)
            {
                ext = new Extents2d(Point2d.Origin.Convert2D(420 * i).Convert2D(0, -297 * pageNo), Point2d.Origin.Convert2D(0, -297 * pageNo));
                lasTb = DrawBeamTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                 Extensions.curFont, scale, divDic[i], typeName, structureName, capLength, "", type, i);
                //lasTb = DrawColumnTable(db, ref ext, M1.Convert3D(), divDic[i].Count + 2,
                //    Extensions.curFont, scale, divDic[i], typeName, structureName, pierHeight, pierName, type, i, title);
                Extents2d extMerge = new Extents2d();
                //Common.CreateLayout(db, "基础数据表", ext, extMerge, scale, 1);

                if (i == divDic.Count - 1)
                {
                    // 绘制合并表格
                    RebarCollection listBack = new RebarCollection();
                    listBack = ret.RebarList;
                    List<string> mergeList = new List<string>();
                    mergeList.Add("Materials");
                    mergeList.Add("Materials");
                    mergeList.Add("Unit");
                    mergeList.Add("Weight(kg)");
                    mergeList.Add("Total(kg)");

                    Point3d pt = M1.Convert3D(420 * i + (lasTb.Width - 226) * 0.5, /*-20*/-lasTb.Height - 40 * scale);
                    Table tb = PloterTable.DrawMergeBeamTable(db, ret, eType, ref extMerge, pt, mergeList,
                      Extensions.curFont, scale);
                    double width = 0;
                    double height = 0;
                    if (tb != null)
                    {
                        width = tb.Width;
                        height = tb.Height;
                        string str1 = string.Format("QUANTITIES OF TYPICAL CROSS BEAM FOR '{0}' OF {1}", pierName, title);
                        string str2 = "";
                        TextPloter.PrintScaleDoubleSideText(db, pt.Convert2D(width / 2, 8 * scale), 3, str1, str2, ref extMerge, scale, Extensions.curFont);
                    }
                    double h1 = ext.L();
                    double h2= extMerge.L();
                    if (h1 + h2 > 265)
                    {
                        Common.CreateLayoutNew(db, "盖梁钢筋数据表", ext, scale, 1, pageNo, i);
                        Common.CreateLayoutNew(db, "盖梁钢筋数据表", extMerge, scale, 1, pageNo, i+1);
                    }
                    else
                    {
                        Common.CreateLayoutNew(db, "盖梁钢筋数据表", ext, extMerge, scale, 1, pageNo, i);
                    }
                }
                else
                    Common.CreateLayoutNew(db, "盖梁钢筋数据表", ext, scale, 1, pageNo, i);
            }
            #endregion
        }
       
    
        /// <summary>
        /// 绘制盖梁表格
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="rowNum"></param>
        /// <param name="txtStyle"></param>
        /// <param name="scale"></param>
        /// <param name="tbValue"></param>
        /// <param name="typeName"></param>
        /// <param name="structureName"></param>
        /// <param name="capLength"></param>
        /// <param name="pierName"></param>
        /// <param name="type"></param>
        /// <param name="pageCount"></param>
        /// <returns></returns>
        public static Table DrawBeamTable(Database db, ref Extents2d ext, Point3d startPoint,
int rowNum, string txtStyle, double scale, RebarCollection tbValue, string typeName, string structureName,
string capLength, string pierName, FDEE.Model.eSubType type, int pageCount = 0)
        {
            if (typeName.ToString().Contains("PE") || typeName.ToString().Contains("PTE"))
            {
                typeName = typeName.ToString().Replace("C", "").Replace("A", "").Replace("B", "");
                typeName = typeName.Substring(0, typeName.Length - 1) + "-" + typeName.Substring(typeName.Length - 1);
                //if (column.Contains("RP11") || column.Contains("RP12") || column.Contains("RP13") || column.Contains("RP14"))
                //typeName = "C-" + type + eHeightTyp.ToString().Replace("1", "*");
            }
            //表格表头
            List<string> headName = new List<string>();
            headName.Add("Bar\\PMark");
            headName.Add("Reinf.\\PType");
            headName.Add("Sharp Configuration");
            headName.Add("Typical\\PFormula");
            headName.Add("R\\P(mm)");
            headName.Add("d\\P(mm)");
            headName.Add("r\\P(mm)");
            headName.Add("h\\P(mm)");
            headName.Add("n\\P(mm)");
            headName.Add("Lx\\P(mm)");
            headName.Add("A\\P(mm)");
            headName.Add("B\\P(mm)");
            headName.Add("C\\P(mm)");
            headName.Add("D\\P(mm)");
            headName.Add("Quantity\\P(No./Ea.)");
            headName.Add("Length\\P(m./Ea.)");
            headName.Add("Total Length\\P(m)");
            headName.Add("Unit Weight\\P(kg/m)");
            headName.Add("Total Weight\\P(kg)");
            tbH = 0;
            int cuRCount = 0;//当前页行高小于块高度的数量
            int curAllRow = 0;//当前页行数
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
                BlockTableRecord modelSpace = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace],
                    OpenMode.ForWrite) as BlockTableRecord;

                ObjectId id;
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                id = st[txtStyle];
                //int rowNum = tbValue.Count + 2;
                // 创建table 
                startPoint = startPoint.Convert3D(420 * pageCount);
                Table tb = new Table();
                int colNum = headName.Count;
                tb.SetSize(rowNum, colNum);       // 设置几行几列
                tb.Position = startPoint;
                tb.GenerateLayout();
                #region 第一页
                #region 第一行 标题
                tb.Cells[0, 0].TextString = String.Format("TABLE REINFORCEMENT BAR LIST TYPICAL CROSS BEAM PIER TYPE {0}(LENGTH={1}M)",
                     typeName.Replace("B", ""), capLength);
                tb.Cells[0, 0].Contents[0].TextHeight = 2.5 * scale;
                tb.Cells[0, 0].Alignment = CellAlignment.MiddleCenter;
                tb.Cells[0, 0].Contents[0].Rotation = 0;
                //tb.Cells[0, 0].Borders.Horizontal.Margin = 1 * scale;
                tb.Cells[0, 0].Contents[0].TextStyleId = id;
                #endregion
                tb.Rows[0].Height = 9 * scale;

                #region 第二行 表格标题
                for (int i = 0; i < colNum; ++i)
                {
                    tb.Cells[1, i].TextString = headName[i]; //获取i行j列数据
                    tb.Cells[1, i].Contents[0].TextHeight = 2.5 * scale;
                    tb.Cells[1, i].Alignment = CellAlignment.MiddleCenter;
                    tb.Cells[1, i].Contents[0].Rotation = 0;
                    tb.Cells[1, i].Borders.Horizontal.Margin = 1 * scale;
                    tb.Cells[1, i].Contents[0].TextStyleId = id;
                }
                #endregion

                tb.Rows[1].Height = 14 * scale;

                #region 设置表格值
                if (tbValue.Count > 0)
                {
                    for (int m = 0; m < tbValue.Count; m++)
                    {
                        try
                        {
                            //
                            string value = "";
                            int n = 0;
                            value = tbValue[m].MBarMark.ToString();
                            if (tbValue[m].SBarMark != 0)
                                value = tbValue[m].MBarMark.ToString() + "." + tbValue[m].SBarMark.ToString() + tbValue[m].CBarMark;
                            else
                                value = tbValue[m].MBarMark.ToString() + tbValue[m].CBarMark;
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            n++;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Diameter.ToString(); //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //Formula
                            n = n + 2;
                            tb.Cells[m + 2, n].TextString = tbValue[m].Formula == null ? "-" : tbValue[m].Formula; //获取i行j列数据
                            tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                            tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                            tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                            tb.Cells[m + 2, n].Contents[0].TextStyleId = id;

                            //R
                            n++;
                            value = "";
                            if (tbValue[m].R != 0)
                                value = tbValue[m].R.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //d
                            n++;
                            value = "";
                            if (tbValue[m].Diameter != 0)
                            {
                                value = System.Text.RegularExpressions.Regex.Replace(tbValue[m].Diameter.ToString(), @"[^0-9]+", "");
                            }
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //r
                            n++;
                            value = "";
                            if (tbValue[m].r != 0)
                                value = tbValue[m].r.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //h
                            n++;
                            value = "";
                            if (tbValue[m].h != 0)
                                value = tbValue[m].h.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //n
                            n++;
                            value = "";
                            if (tbValue[m].n != 0)
                                value = tbValue[m].n.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Lx
                            n++;
                            value = "";
                            if (tbValue[m].Lx != 0)
                                value = tbValue[m].Lx.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //A
                            n++;
                            value = "";
                            if (tbValue[m].A != 0)
                                value = tbValue[m].A.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //B
                            n++;
                            value = "";
                            if (tbValue[m].B != 0)
                                value = tbValue[m].B.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //C
                            n++;
                            value = "";
                            if (tbValue[m].C != 0)
                                value = tbValue[m].C.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //D
                            n++;
                            value = "";
                            if (tbValue[m].D != 0)
                                value = tbValue[m].D.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Quantity
                            n++;
                            value = "";
                            if (tbValue[m].Quantity != 0)
                                value = tbValue[m].Quantity.ToString();
                            tb.Cells[m + 2, n].TextString = value; //获取i行j列数据
                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //Length
                            n++;
                            value = "";
                            if (tbValue[m].Length != 0)
                                value = tbValue[m].Length.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value)); //获取i行j列数据
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalLength
                            n++;
                            value = "";
                            if (tbValue[m].TotalLength != 0)
                                value = tbValue[m].TotalLength.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //UnitWeight
                            n++;
                            value = "";
                            if (tbValue[m].UnitWeight != 0)
                                value = tbValue[m].UnitWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }

                            //TotalWeight
                            n++;
                            value = "";
                            if (tbValue[m].TotalWeight != 0)
                                value = tbValue[m].TotalWeight.ToString("0.000").Trim();

                            if (!string.IsNullOrWhiteSpace(value))
                            {
                                tb.Cells[m + 2, n].TextString = value;// string.Format("{0:N3}", double.Parse(value));
                                tb.Cells[m + 2, n].Contents[0].TextHeight = 2 * scale;
                                tb.Cells[m + 2, n].Alignment = CellAlignment.MiddleCenter;
                                tb.Cells[m + 2, n].Borders.Horizontal.Margin = 1 * scale;
                                tb.Cells[m + 2, n].Contents[0].TextStyleId = id;
                            }
                            //if (tbValue[m].ShapeConfg.ToString().Contains("MO135"))
                            //    _blcName = "MO135";
                            //else 
                            if (!tbValue[m].ShapeConfg.ToString().Contains("MPC"))
                            {
                                if (tbValue[m].ShapeConfg.ToString().Contains("MO"))
                                    _blcName = "MO";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUC"))
                                    _blcName = "MUC";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MUR"))
                                    _blcName = "MUR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MU"))
                                    _blcName = "MU";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZR"))
                                    _blcName = "MSZR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MSZ"))
                                    _blcName = "MSZ";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXCR"))
                                    _blcName = "MIXCR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXC"))
                                    _blcName = "MIXC0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXAR"))
                                    _blcName = "MIXAR0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MIXA"))
                                    _blcName = "MIXA0";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MA"))
                                    _blcName = "MA";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCT"))
                                    _blcName = "MCT";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCB"))
                                    _blcName = "MCB";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCR"))
                                    _blcName = "MCR";
                                else if (tbValue[m].ShapeConfg.ToString().Contains("MCL"))
                                    _blcName = "MCL";
                                db.CopyBlockFromFile(_dwgPath, _blcName);

                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 14 * scale + 14 * m + 7)), 0.8, _blcName, _dwgPath, 0);
                            }
                            else
                            {
                                _blcName = "MPC";
                                db.CopyBlockFromFile(_dwgPath, _blcName);

                                BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8 * 3 * scale, -(9 * scale + 14 * scale + 14 * m + 7)), 1, _blcName, _dwgPath, 0);
                            }
                        }
                        catch (Exception ex)
                        { }
                    }
                }

                #endregion

                #region 表格添加数据

                #endregion

                #region 设置列宽
                // 设置列宽
                for (int i = 0; i < colNum; ++i)
                {
                    if (i == 0)
                        tb.Columns[i].Width = 4 * 3 * scale;
                    else if (i == 1)
                        tb.Columns[i].Width = 5 * 3 * scale;
                    else if (i == 2)
                        tb.Columns[i].Width = 16 * 3 * scale;
                    else if (i == 3)
                        tb.Columns[i].Width = 11 * 3 * scale;
                    else if (i > headName.Count - 4)
                        tb.Columns[i].Width = 9 * 3 * scale;
                    else if (i > headName.Count - 6)
                        tb.Columns[i].Width = 8 * 3 * scale;
                    else
                        tb.Columns[i].Width = 4 * 3 * scale;
                }
                #endregion

                //行高
                for (int i = 2; i < rowNum; ++i)
                {
                    tb.Rows[i].Height = 14 * scale;
                }

                #region 列单元格合并

                ////合并数据定义
                //Dictionary<int, int> dic = new Dictionary<int, int>();
                //int rowIndex = 0;
                //int num = 0;
                //string stShape = tbValue[0].ShapeConfg.ToString();//要合并的类型
                //string stDia = tbValue[0].Diameter.ToString();//要合并的钢筋直径
                //for (int i = 0; i < tbValue.Count; ++i)
                //{
                //    //同样的直径和类型合并
                //    if (tbValue[i].ShapeConfg.ToString() == stShape&& tbValue[i].Diameter.ToString() == stDia)
                //    {
                //        num++;
                //    }
                //    else
                //    {

                //        dic.Add(rowIndex, num);
                //        num = 1;
                //        rowIndex = i;
                //        //下一条要合并的直径和类型
                //        stDia = tbValue[i].Diameter.ToString();
                //        stShape = tbValue[i].ShapeConfg.ToString();
                //    }
                //    if (i == tbValue.Count - 1)
                //        dic.Add(rowIndex, num);
                //}

                // 列单元格合并
                //int topRow = 2;

                //List<CellRange> cellList = new List<CellRange>();

                //foreach (KeyValuePair<int, int> pr in dic)
                //{
                //    curAllRow += pr.Value;
                //    lastMegerHeight = pr.Value * 6.5 * scale;
                //    tb.Cells[topRow, 2].Alignment = CellAlignment.MiddleCenter;
                //    if (pr.Value < 4)
                //    {
                //        for (int i = 0; i < pr.Value; i++)
                //        {
                //            tb.Rows[topRow+i].Height = intervalHeight / pr.Value;                            
                //        }
                //        cuRCount++;
                //        curAllRow -= pr.Value;
                //        lastMegerHeight =32 * scale;

                //    }

                //    db.CopyBlockFromFile(_dwgPath, _blcName);
                //    BlockTool.InsertBlockReference(startPoint.Convert3D(4 * 3 * scale + 5 * 3 * scale + 8*3 * scale, -(7 * scale + 12 * scale + intervalHeight * cuRCount+ 6.5  * curAllRow - lastMegerHeight * 0.4)), 1, _blcName, _dwgPath, 0);
                //    CellRange range = CellRange.Create(tb, topRow, 2, topRow + pr.Value - 1, 2);


                //    cellList.Add(range);
                //    topRow += pr.Value;

                //}
                //foreach (CellRange range in cellList)
                //{
                //    tb.MergeCells(range);
                //}

                #endregion

                tb.Layer = "细线";
                tb.LineWeight = LineWeight.LineWeight013;
                tb.ColorIndex = 4;
                modelSpace.AppendEntity(tb);
                tr.AddNewlyCreatedDBObject(tb, true);
                ext = ext.Add(new Extents2d(tb.Bounds.Value.MinPoint.Convert2D(), tb.Bounds.Value.MaxPoint.Convert2D()));

                #region  边框粗线设置
                List<Point2d> pList = new List<Point2d>();
                Point2d pt1 = startPoint.Convert2D();
                pList.Add(pt1);
                Point2d pt2 = pt1.Convert2D(0, -tb.Height);
                pList.Add(pt2);
                Point2d pt3 = pt1.Convert2D(tb.Width, -tb.Height);
                pList.Add(pt3);
                Point2d pt4 = pt1.Convert2D(tb.Width, 0);
                pList.Add(pt4);
                PolylinePloter.AddPolylineByList(db, ref ext, pList, "粗线", 2);
                #endregion

                #endregion

                #region 其他页

                #endregion
                tr.Commit();
                return tb;
            }
        }

        /// <summary>
        /// 盖梁分页
        /// </summary>
        /// <param name="listRebar"></param>
        /// <param name="scale"></param>
        /// <param name="divDic"></param>
        public static void CalcBeamPage(RebarCollection listRebar, double scale, ref List<RebarCollection> divDic)
        {
            RebarCollection div = new RebarCollection();
            int num = 0;
            for (int i = 0; i < listRebar.Count; ++i)
            {
                //同样的直径和类型合并
                if (num < 15)
                {
                    div.Add(listRebar[i]);
                    num++;

                }
                else
                {
                    divDic.Add(div);
                    div = new RebarCollection();
                    num = 1;
                    div.Add(listRebar[i]);
                }
            }
            divDic.Add(div);

        }
    }


}
